package sctu.edu.java.year2016.team01.chenhong.day20160530.chapter9_1;

/**
 * Created by Administrator on 2016/5/30.
 * 创建一个类，并在类中创建一个成员内部类，通过成员内部类计算1到任意数的 和的操作，并在外部类中进行测试
 *
 */
import java.util.Scanner;


//外部类
public class Sum {


    //内部类
    class InnerSum {

        int i;
        int s = 0;//s为和


        public int f(int j) {


            for (i = 1; i <= j; i++) {
                s += i;

            }
            return s;
        }



}




    public static void main(String[] args) {
        System.out.println("请输入你想从1加到好多：");
        Scanner scan = new Scanner(System.in);
         int j=scan.nextInt();




        Sum.InnerSum innerSum  = new Sum().new InnerSum();

        System.out.println("请输入你想从1加到" + j + "的和是:"+innerSum.f( j));


    }

}